package com.bluemsun.naturallanguageprocessing.controller;

import com.bluemsun.naturallanguageprocessing.common.ServerResponse;
import com.bluemsun.naturallanguageprocessing.dao.BrowseMapper;
import com.bluemsun.naturallanguageprocessing.entity.UserApi;
import com.bluemsun.naturallanguageprocessing.service.IBrowseService;
import com.bluemsun.naturallanguageprocessing.util.ConductRedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.Resources;
import javax.servlet.http.HttpServletRequest;
import java.util.logging.Logger;

/**
 * @author ：hj
 * @date ：Created in 2021/4/16 13:55
 * @description：浏览记录
 * @modified By：
 * @version: $
 */
@RequestMapping("/Browse")
@RestController
public class BrowseController {

    @Autowired
    IBrowseService iBrowseService;
    @Autowired
    ConductRedisUtil conductRedisUtil;
    /**
     * @author     ：hj
     * @date       ：Created in 2021/4/18 15:59
     * @description：获取浏览记录
     * @modified By：
     * @version:
     */
    @GetMapping(value = "/get")
    @ResponseBody
    public ServerResponse<Object> getBrowse(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum, HttpServletRequest request){
        return iBrowseService.getBrowse(request,pageSize, pageNum);
    }
    /**
     * @author     ：hj
     * @date       ：Created in 2021/4/18 15:59
     * @description：删除单条浏览记录
     * @modified By：
     * @version:
     */
    @GetMapping(value="/delete")
    @ResponseBody
    public ServerResponse<Object> deleteBrowse(@RequestParam("id")Integer id){
        return iBrowseService.deleteBrowse(id);
    }

    @GetMapping(value="/deleteall")
    @ResponseBody
    public ServerResponse<Object> deleteAllBrowse(HttpServletRequest request){
        UserApi userApi =(UserApi) conductRedisUtil.getUserFromRedis(request.getHeader("token"));
        return iBrowseService.deleteAllBrowse(userApi.getId());
    }
}
